<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录页面</title>
    <script src="../util/axios.min.js"></script>
    <style>
        /* 重置默认的边距和填充 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: Arial, sans-serif;
            background: url('../images/vmbg2.png') center/cover no-repeat fixed; /* 使用背景图像 */
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }

        .login-container {
            text-align: center;
        }

        .login-card {
            background: rgba(255, 255, 255, 0.8); /* 添加半透明的背景颜色 */
            box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
            border-radius: 8px;
            padding: 20px;
            width: 300px;
            max-width: 100%;
        }

        .login-card h2 {
            color: #333;
        }

        .input-container {
            margin-bottom: 20px;
        }

        label {
            display: block;
            text-align: left;
            color: #555;
            font-weight: bold;
        }

        input[type="text"],
        input[type="password"] {
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }



        .button-container {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        button{
            background: linear-gradient(to right,  #007bff, #0056b3);
            color: #fff;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background 0.3s ease;
        }

        button:hover {
            background: linear-gradient(to left,  #007bff, #0056b3);
        }

        p {
            margin-top: 10px;
        }
    </style>
</head>
<body>
<div class="login-container">
    <div class="login-card">
        <form >
            <div class="input-container">
                <h2>添加题目</h2>
                <label for="questionContent">题目内容</label>
                <input type="text" id="questionContent"  placeholder="请输入题目内容" required>
            </div>


            <div class="input-container">
                <label for="optionA">选项A</label>
                <input type="text" id="optionA"  placeholder="请输入选项" required>
            </div>
            <div class="input-container">
                <label for="optionB">选项B</label>
                <input type="text" id="optionB"  placeholder="请输入选项" required>
            </div>
            <div class="input-container">
                <label for="optionC">选项C</label>
                <input type="text" id="optionC"  placeholder="请输入选项" required>
            </div>
            <div class="input-container">
                <label for="optionD">选项D</label>
                <input type="text" id="optionD"  placeholder="请输入选项" required>
            </div>
            <div class="input-container">
                <label for="questionAnswer">答案</label>
                <input type="text" id="questionAnswer"  placeholder="请输入答案选项" required>
            </div>
            <div class="button-container">
                <button type="button" onclick="update()">添加</button>
                <button type="reset">重置</button>
            </div>
        </form>
    </div>
</div>
</body>
<script >
    function update() {
        const questionContent=document.getElementById("questionContent").value
        const optionA=document.getElementById("optionA").value
        const optionB=document.getElementById("optionB").value
        const optionC=document.getElementById("optionC").value
        const optionD=document.getElementById("optionD").value
        const questionAnswer=document.getElementById("questionAnswer").value

        // 添加请求拦截器
        axios.interceptors.request.use(function (config) {
            config.headers.token = localStorage.getItem("token")
            // 在发送请求之前做些什么
            return config;
        });
        axios({
            method: 'post',
            url: 'http://localhost:8080/questionBank/addQuestion',
            data: {
                questionContent:questionContent,
                questionAnswer: questionAnswer,
                questionOptions:JSON.stringify({A:optionA,B:optionB, C:optionC, D:optionD})
            }
        }).then((resp)=>{
            if (resp.data.code===200){
                window.location.reload();
                alert("添加成功")
            }
        });
    }
</script>
</html>
